home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 60.zip / BS1 part 60 / Highspeed pascal.adf / HSPascal / AmigaDemos / WindowDemo.pas < prev   
Pascal/Delphi Source File  |  1991-12-31  |  7KB  |  150 lines

  1. {--------------------------------------------------------------------------
  2.  
  3.                      HighSpeed Pascal for the Amiga
  4.  
  5.                               WINDOW DEMO
  6.  
  7.                   Programmed by Martin Eskildsen 1991
  8.  
  9.                   Copyright (c) 1991 by D-House I ApS
  10.                          All rights reserved
  11.  
  12.  
  13.   Version : Date (dd.mm.yy) : Comment
  14.   -----------------------------------
  15.     1.00 : 20.07.91 : First version
  16.     1.01 : 17.09.91 : Modified for new libraries
  17.     1.02 : 06.11.91 : Final for first release
  18.  
  19. --------------------------------------------------------------------------}
  20.  
  21. program WindowDemo;
  22.  
  23. uses Init, Intuition, Graphics;
  24.  
  25. label
  26.   1;                                      { Disaster branch-out }
  27.  
  28. const
  29.   MaxWindows = 7;                         { Can't do more because of screen size }
  30.  
  31. var
  32.   w1def     : tNewWindow;                 { Defs for window 1 }
  33.   wdef      : tNewWindow;                 { Defs for other windows }
  34.   w         : array [1..MaxWindows] of pWindow;   { Window records }
  35.   i, j      : integer;                    { Index }
  36.  
  37. begin
  38.   if PrepareEnvironment('Window') then begin     { Init Demo environment }
  39.  
  40.     Message('First, a simple window with borders only');
  41.     with w1def do begin                   { Set up window: }
  42.       LeftEdge       := 20;
  43.       TopEdge        := Init.TopOffset;   { Start below info window }
  44.       Width          := 210;
  45.       Height         := 75;
  46.       DetailPen      := 0;                { Color to use for details }
  47.       BlockPen       := 1;                { and blocks }
  48.       Title          := NIL;              { Window has no title bar, so NIL }
  49.       Flags          := SMART_REFRESH or  { Save parts in RAM }
  50.                         NOCAREREFRESH;    { Don't want no refresh messages }
  51.       IDCMPflags     := 0;                { Don't want any messages at all! }
  52.       Type_          := CUSTOMSCREEN;     { Put it on the CUSTOMSCREEN }
  53.       FirstGadget    := NIL;              { No gadgets attached }
  54.       CheckMark      := NIL;              { Usual check mark }
  55.       Screen         := Init.BaseScreen;  { The custom screen to use }
  56.       BitMap         := NIL;              { No special bitmap for window }
  57.       MinWidth       := Width;            { Values for user's resizing of }
  58.       MinHeight      := Height;           { window. Aren't used here as the }
  59.       MaxWidth       := MinWidth;         { window can't be resized }
  60.       MaxHeight      := MaxHeight
  61.     end;
  62.     w[1] := OpenWindow(@w1def);           { Open the window }
  63.     if Panic(w[1] = NIL, 'Could not open window 1!')  { Couldn't! }
  64.       then goto 1;                                    { Let's get out of here! }
  65.  
  66.     with w[1]^ do begin                   { Put some text in the window: }
  67.       Move_(RPort, 10,20);                { (x,y) for lower left corner }
  68.       Text_(RPort, 'Window with borders only',  { The string to write }
  69.            24)                                  { The length of the string! }
  70.     end;
  71.  
  72.     Message('Then with the usual gadgets');
  73.     wdef := w1def;                        { Use same def as w[1] }
  74.     with wdef do begin                    { but change it a bit: }
  75.       inc(TopEdge,   15);                 { Move a bit down and }
  76.       inc(LeftEdge,  15);                 { to the right }
  77.       MinWidth   :=  40;                  { Make it resizable }
  78.       MinHeight  :=  20;
  79.       MaxWidth   := Init.ScrWidth;
  80.       MaxHeight  := Init.ScrHeight;
  81.       flags := flags or WINDOWCLOSE or    { Want the Close gadget, }
  82.                WINDOWDRAG or              { drag gadget, }
  83.                WINDOWDEPTH or             { depth arrangement gadgets, }
  84.                WINDOWSIZING;              { size gadget, too }
  85.       IDCMPflags := CLOSEWINDOW_;         { Want to know if user }
  86.                                           { clicked the Close gadget. }
  87.                                           { Note the underscore '_' }
  88.       Title := CStrConstPtr('Window 2'#0)
  89.     end;
  90.     w[2] := OpenWindow(@wdef);            { Open window 2 }
  91.     if Panic(w[2] = NIL, 'Could not open window 2!') then goto 1;
  92.  
  93.     DisableClose(w[2]);
  94. { This is funny! Now, if I want to be able to sense the Close gadget I have
  95.   to have the IDCMPflags set when opening the window. But I don't want to
  96.   sense this message right now, so I clear the CLOSEWINDOW_ flag immediately
  97.   upon creating the window.
  98.   This makes the program behave properly if the user clicks the "wrong"
  99.   Close gadget (i.e. in the wrong window) when there are two windows on the
  100.   screen. Try to remove DisableClose and play around with the Close clicks }
  101.  
  102.     Message('Nice name, right? Let''s call it something else');
  103.     SetWindowTitles(w[2],
  104.                     CStrConstPtr('Forty-two!'),
  105.                     ptr(-1));             { Don't change screen title }
  106.  
  107.     Inform('Say good-bye to window 2 by clicking its Close gadget');
  108.     WaitClose(w[2]);                      { Wait for user to click Close gadget }
  109.     CloseWindow(w[2]);                    { Close window 2 }
  110.  
  111.     Message('The application can resize the window (now six times)');
  112.     for i := 1 to 6 do SizeWindow(w[1], 20, 10);   { Delta x and y }
  113.  
  114.     Message('And change its position ten times 20 pixels');
  115.     for i := 1 to 10 do MoveWindow(w[1], 20, 0);   { Delta x and y }
  116.     
  117.     Message('Seen enough of that window, right? Let''s throw it away!');
  118.     CloseWindow(w[1]);
  119.     
  120.     Message('We shall now create a "stack" of windows');
  121.     wdef := w1def;
  122.     wdef.flags := wdef.flags or WINDOWDRAG or WINDOWDEPTH;
  123.     for i := 1 to MaxWindows do begin
  124.       with wdef do begin
  125.         inc(TopEdge,  10);
  126.         inc(LeftEdge, 20);
  127.         Title := CStrConstPtr('Window ' + chr(i + ord('@')) + #0)
  128.       end;
  129.       w[i] := OpenWindow(@wdef);
  130.       if Panic(w[i] = NIL, 'Error while opening a window!') then goto 1;
  131.       with w[i]^ do begin              { Put text in window }
  132.         Graphics.Move_(RPort, 3, 20);  { at (3,20) }
  133.         for j := 1 to 24 do            { 24 letters: Window 1 = AAAAA... }
  134.                                        {        Window 2 = BBBBB... etc. }
  135.           Graphics.Text_(RPort, chr(i + ord('@')), 1)
  136.       end
  137.     end;
  138.  
  139.     Message('Now the application will "cycle" the stack');
  140.     for i := MaxWindows downto 1 do WindowToFront(w[i]);
  141.     
  142.     Message('Phew! Let''s close those windows again');
  143.     for i := MaxWindows downto 1 do CloseWindow(w[i]);
  144.  
  145.     1:                            { Where to go if the world gets "funny" }
  146.     CloseDown                     { Deinit Demo environment }
  147.   
  148.   end
  149. end.
  150.